/* 找非递减序列的两数之和等于target
 * https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted/
 * Note: The returned array must be malloced, assume caller calls free().
 */

int* twoSum(int* numbers, int numbersSize, int target, int* returnSize){
    int *res = (int *)malloc(sizeof(int) * 2);
    *returnSize = 2;
    int left = 0;
    int right = numbersSize - 1;

    while (left < right) {
        if (numbers[left] + numbers[right] == target) {
            res[0] = left + 1;
            res[1] = right + 1;
            break;
        }
        if (numbers[left] + numbers[right] > target) {
            right--;
        } else {
            left++;
        }
    }

    return res;
}